//
//  MBProcessHUDHelper.m
//  MaiQuan
//
//  Created by ZHANG Tianle on 4/30/12.
//  Copyright (c) 2012 MyQuan. Inc.. All rights reserved.
//

#import "MBProgressHUDHelper.h"

@implementation MBProgressHUDHelper

+ (MBProgressHUD*)popUpMBProcessHUD:(UIView*)rootView delegate:(id<MBProgressHUDDelegate>)delegate
{
    MBProgressHUD* progressHUD = [[[MBProgressHUD alloc] initWithView:rootView] autorelease];
    [rootView addSubview:progressHUD];
    
    progressHUD.showMsgType = MBProgressHUDNormalMsgType;
    progressHUD.dimBackground = YES;
    progressHUD.labelText = @"";
    progressHUD.delegate = delegate;
        
    return progressHUD;
}

+ (void)changeToMBSuccessMode:(MBProgressHUD*)progressHUD customMsg:(NSString*)customMsg afterDelay:(NSTimeInterval)afterDelay
{
    if (progressHUD == nil) 
    {
        return;
    }
    
    [progressHUD show:YES];
    progressHUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
    progressHUD.mode = MBProgressHUDModeCustomView;
    progressHUD.showMsgType = MBProgressHUDSuccessMsgType;
    progressHUD.labelText = customMsg;
    [progressHUD show:YES];
	[progressHUD hide:YES afterDelay:afterDelay];
}

+ (void)changeToMBSuccessMode:(MBProgressHUD*)progressHUD customMsg:(NSString*)customMsg
{
    [self changeToMBSuccessMode:progressHUD customMsg:customMsg afterDelay:1.5f];
}

+ (void)changeToMBFailedMode:(MBProgressHUD*)progressHUD customMsg:(NSString*)customMsg afterDelay:(NSTimeInterval)afterDelay
{
    if (progressHUD == nil) 
    {
        return;
    }

    [progressHUD show:YES];
    progressHUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Error.png"]] autorelease];
    progressHUD.mode = MBProgressHUDModeCustomView;
    progressHUD.labelText = customMsg;
    progressHUD.showMsgType = MBProgressHUDFailedMsgType;
	[progressHUD hide:YES afterDelay:afterDelay];
}

+ (void)changeToMBFailedMode:(MBProgressHUD*)progressHUD customMsg:(NSString*)customMsg
{
    [self changeToMBFailedMode:progressHUD customMsg:customMsg afterDelay:1.5f];
}

@end
